/*
 * Copyright (c) 2025. hallele, Inc All rights reserved.
 */

package cn.hallele.ms.starter.web.framework.service.impl;

import cn.hallele.infrastructure.metadata.io.User;
import cn.hallele.infrastructure.util.NetUtil;
import cn.hallele.infrastructure.util.bean.LoginUser;
import cn.hallele.ms.starter.web.framework.bo.ActionOrder;
import cn.hallele.ms.starter.web.framework.context.ActionContext;
import cn.hallele.ms.starter.web.framework.service.ActionInitializeService;
import cn.hallele.ms.starter.web.framework.service.CustomerActionInitializeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * hallele_mc_core
 *
 * @author anle5
 * @since 2025/3/9 18:04
 */
@Slf4j
@Service
public class ActionInitializeServiceImpl implements ActionInitializeService {
    @Autowired(required = false)
    private CustomerActionInitializeService customerActionInitializeService;

    /**
     * 初始化上下文时获取用户信息的
     *
     * @return UserInfo
     */
    @Override
    public User getUserInfo() {
        if (customerActionInitializeService != null) {
            return customerActionInitializeService.getCustomerUserInfo();
        }

        // 兼容非网关类微服务
        LoginUser loginUser = NetUtil.getLoginUser();
        if (loginUser != null) {
            return User.builder()
                    .tenantId(loginUser.getTenantId())
                    .id(loginUser.getId())
                    .username(loginUser.getUsername())
                    .email(loginUser.getEmail())
                    .phoneNumber(loginUser.getPhoneNumber())
                    .build();
        }
        return null;
    }

    /**
     * 订单生成，需要掉订单服务生成订单
     *
     * @param context 上下文
     * @return 订单
     */
    @Override
    public ActionOrder createActionOrder(ActionContext context) {
        return null;
    }

    /**
     * 取消订单
     *
     * @param context 上下文
     * @return 订单
     */
    @Override
    public ActionOrder cancelActionOrder(ActionContext context) {
        return null;
    }

    /**
     * 完成订单
     *
     * @param context 上下文
     * @return 订单
     */
    @Override
    public ActionOrder completeActionOrder(ActionContext context) {
        return null;
    }
}
